using System;
using System.Net;

namespace ITMSClient
{
	/// <summary>
	/// Encapsulates the XML data and HTTP response from 
	/// a request to the iTunes server.
	/// </summary>
	public class ITMSContent
	{
		private HttpWebResponse _webResponse;
		private WebException	_webException;
		private string			_xml;

		#region Constructors
		/// <summary>
		/// Creates a new <see cref="ITMSContent"/> instance.
		/// </summary>
		/// <param name="response">Response.</param>
		/// <param name="Xml">Xml.</param>
		public ITMSContent(HttpWebResponse response, string Xml)
		{
            //MediaPortal.GUI.Library.Log.Info("creating ITMSContent");
			_webResponse = response;
			_xml = Xml;
            //MediaPortal.GUI.Library.Log.Info("Finished creating ITMSContent");
		}

		/// <summary>
		/// Creates a new <see cref="ITMSContent"/> instance.
		/// </summary>
		/// <param name="exception">Exception.</param>
		public ITMSContent(WebException exception)
		{
			_webException = exception;
			_xml = String.Empty;
		}
		#endregion

		#region Public Properties
		/// <summary>
		/// Gets a value indicating whether this instance is valid.
		/// </summary>
		/// <value>
		/// 	<c>true</c> if this instance is valid; otherwise, <c>false</c>.
		/// </value>
		public bool IsValid
		{
			get { return ( _xml.Length != 0 && 
					       _webException == null && 
					       _webResponse != null && 
					       _webResponse.StatusCode == HttpStatusCode.OK); }
		}
		
		/// <summary>
		/// Gets the Xml.
		/// </summary>
		/// <value></value>
		public string Xml
		{
			get { return _xml; }
		}

		/// <summary>
		/// Gets the page info.
		/// </summary>
		/// <value></value>
		public HttpWebResponse WebResponse
		{
			get { return _webResponse; }
		}

		/// <summary>
		/// Gets the exception.
		/// </summary>
		/// <value></value>
		public WebException Exception
		{
			get { return _webException; }
		}
		#endregion
	}
}
